import { http } from '@/server'
import type { EvaluateResult } from './detail/interface'
import type { HttpResponsePending } from '@/server/interface'
import type { ClassDetail, Evaluate } from './index/interface'
import type { Answer, EvaluateDetail } from './write/interface'

/**
 * 获取班级评估列表
 * @param id 班级ID
 * @returns
 */
export const fetchClassEvaluates = (id: number): HttpResponsePending<Evaluate[]> =>
    http.get(`/country/group/evaluate-list/${id}`)

/** 获取班级详情 */
export const fetchClassDetail = (id: number): HttpResponsePending<ClassDetail> =>
    http.get(`/country/group/info/${id}`)

/** 获取可发布评估表 */
export const fetchPublishableEvaluates = (
    id: number,
): HttpResponsePending<Record<string, string>> => http.get(`/engineer/teacher/evaluate/${id}`)

/**
 * 根据评估表获取教学内容
 * @param gid 班级ID
 * @param eid 评估表ID
 * @returns
 */
export const fetchTeachContents = (gid: number, eid: number): HttpResponsePending<any> =>
    http.get(`/engineer/teacher/evaluate-lesson/${gid}/${eid}`)

/**
 * 发起评估
 * @param gid 班级ID
 * @param eid 评估表ID
 * @param params
 * @returns
 */
export const publishEvaluate = (gid: number, eid: number, params: Record<string, any>) =>
    http.post(`/engineer/teacher/release-evaluate/${gid}/${eid}`, { ...params })

/**
 * 获取评估问卷详情
 * @param id 表单ID
 * @param gid 班级ID
 * @returns
 */
export const fetchEvaluateDetail = (id: number, gid: number): HttpResponsePending<EvaluateDetail> =>
    http.get(`/engineer/evaluate/info/${id}`, {
        params: { group_id: gid },
    })

/**
 * 提交评估问卷
 * @param id 班级ID
 * @param evaluateId 评估表单ID
 * @param answer 答案
 * @returns
 */
export const submitEvaluate = (id: number, evaluateId: number, listId: number, answer: Answer[]) =>
    http.post(`/engineer/evaluate/submit/${id}/${evaluateId}/${listId}`, {
        answer,
    })

/**
 * 获取培训评价结果
 * @param groupId
 * @param evaluateId
 * @returns
 */
export const fetchEvaluateResult = (
    groupId: number,
    evaluateId: number,
    listId: number,
): HttpResponsePending<EvaluateResult> =>
    http.get(`/engineer/evaluate/result/${groupId}/${evaluateId}/${listId}`)
